/*
 * 案件详情作业记录
 */
import { defineStore } from 'pinia'

// deprecated 请使用 useGlobalStore
export const workRecordStore = defineStore('workRecord', () => {
	// 定义state
	const records = ref([])
	const isClose = ref(false) //是否案件关闭

	// 定义action
	//添加作业记录
	const setRecord = (record) => {
		const i = records.value.findIndex((item) => item.caseId === record.caseId)
		if (i !== -1) {
			records.value.splice(i, 1, record)
			return
		}
		records.value.push(record)
	}
	//获取作业记录
	const getRecord = (id) => {
		return records.value.find((item) => item.caseId === id)
	}
	//删除作业记录
	const delRecord = (id) => {
		const i = records.value.findIndex((item) => item.caseId === id)
		if (i !== -1) {
			records.value.splice(i, 1)
			return
		}
	}
	const setIsclosed = (val) => {
		isClose.value = val
	}
	return {
		records,
		isClose,
		setRecord,
		getRecord,
		delRecord,
		setIsclosed
	}
})

export const useWorkRecordStore = workRecordStore
